package cn.com.zhaoweiping.ie;

import java.io.Serializable;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 数据<br>
 *
 * @author 冰羽
 * @version 2.2.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class RowWrapper implements Serializable {

  List<ExcelField> excelFields;
  private Integer rowIndex;
  private Object rowData;

  /**
   * 获取数据对应的实体类型
   *
   * @return ? extends T
   * @throws NullPointerException
   */
  public Class<?> getEntityType() throws NullPointerException {
    return this.excelFields.stream()
        .filter(ef -> ef.getEntityType() != null)
        .findFirst()
        .get()
        .getEntityType();
  }

  /**
   * RowWrapper不为空判断
   *
   * @return
   */
  public boolean isNotEmpty() {
    return rowIndex != null && rowData != null;
  }
}
